//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.alibaba.druid.pool;

import com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey;
import com.alibaba.druid.pool.PreparedStatementPool.MethodType;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class ElasticSearchDruidPooledConnection extends DruidPooledConnection {
    public ElasticSearchDruidPooledConnection(DruidConnectionHolder holder) {
        super(holder);
    }

    public PreparedStatement prepareStatement(String sql) throws SQLException {
        this.checkState();
        PreparedStatementHolder stmtHolder = null;
        PreparedStatementKey key = new PreparedStatementKey(sql, this.getCatalog(), MethodType.M1);
        boolean poolPreparedStatements = this.holder.isPoolPreparedStatements();
        if (poolPreparedStatements) {
            stmtHolder = this.holder.getStatementPool().get(key);
        }

        if (stmtHolder == null) {
            try {
                stmtHolder = new PreparedStatementHolder(key, this.conn.prepareStatement(sql));
                this.holder.getDataSource().incrementPreparedStatementCount();
            } catch (SQLException var6) {
                this.handleException(var6, sql);
            }
        }

        this.initStatement(stmtHolder);
        DruidPooledPreparedStatement rtnVal = new ElasticSearchDruidPooledPreparedStatement(this, stmtHolder);
        this.holder.addTrace(rtnVal);
        return rtnVal;
    }

    public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
        this.checkState();
        PreparedStatementHolder stmtHolder = null;
        PreparedStatementKey key = new PreparedStatementKey(sql, this.getCatalog(), MethodType.M2, resultSetType, resultSetConcurrency);
        boolean poolPreparedStatements = this.holder.isPoolPreparedStatements();
        if (poolPreparedStatements) {
            stmtHolder = this.holder.getStatementPool().get(key);
        }

        if (stmtHolder == null) {
            try {
                stmtHolder = new PreparedStatementHolder(key, this.conn.prepareStatement(sql, resultSetType, resultSetConcurrency));
                this.holder.getDataSource().incrementPreparedStatementCount();
            } catch (SQLException var8) {
                this.handleException(var8, sql);
            }
        }

        this.initStatement(stmtHolder);
        DruidPooledPreparedStatement rtnVal = new ElasticSearchDruidPooledPreparedStatement(this, stmtHolder);
        this.holder.addTrace(rtnVal);
        return rtnVal;
    }
    public DatabaseMetaData getMetaData() throws SQLException { return new ElasticSearchDatabaseMetaData((Connection)this); }

    private void initStatement(PreparedStatementHolder stmtHolder) throws SQLException {
        stmtHolder.incrementInUseCount();
        this.holder.getDataSource().initStatement(this, stmtHolder.statement);
    }
}
